package com.mzz.structure.flyweight;

/**
 *
 * @author xushijian
 * @date 18/5/24 上午11:47
 */
public class Test {

    public static void main(String[] args) {

        WebSite webSite1 = WebSiteFactory.createWebSite("用户系统");
        User user1 = new User("user1", "pwd1");
        webSite1.use(user1);

        WebSite webSite2 = WebSiteFactory.createWebSite("用户系统");
        User user2 = new User("user2", "pwd2");
        webSite2.use(user2);

        System.out.println("website1 == wesite2 --->" + webSite1.equals(webSite2));

        WebSite webSite3 = WebSiteFactory.createWebSite("用户系统");
        User user3 = new User("user3", "pwd3");
        webSite3.use(user3);

        WebSite webSite4 = WebSiteFactory.createWebSite("业务系统");
        User user4 = new User("user4", "pwd4");
        webSite4.use(user4);

        System.out.println("website1 == wesite2 --->" + webSite3.equals(webSite4));

        WebSite webSite5 = WebSiteFactory.createWebSite("业务系统");
        User user5 = new User("user5", "pwd5");
        webSite5.use(user5);

        WebSite webSite6 = WebSiteFactory.createWebSite("业务系统");
        User user6 = new User("user6", "pwd6");
        webSite6.use(user6);

        System.out.println("webSite5 == webSite6 --->" + (webSite5 == webSite6));

        //ExecutorService e = Executors.newFixedThreadPool(100);
        /**
         * The queue used for holding tasks and handing off to worker
         * threads.  We do not require that workQueue.poll() returning
         * null necessarily means that workQueue.isEmpty(), so rely
         * solely on isEmpty to see if the queue is empty (which we must
         * do for example when deciding whether to transition from
         * SHUTDOWN to TIDYING).  This accommodates special-purpose
         * queues such as DelayQueues for which poll() is allowed to
         * return null even if it may later return non-null when delays
         * expire.
         */
        //private final BlockingQueue<Runnable> workQueue; //线程队列
        //ExecutorService

        // （1）。Integer  示例

        //Integer

        /**
         *
         * public static Integer valueOf(int i)
         * {
         *
         *      //如果是基本数据类型，则直接从缓存中获取 IntegerCache.cache
                if (i >= IntegerCache.low && i <= IntegerCache.high)
                 return IntegerCache.cache[i + (-IntegerCache.low)];
                 return new Integer(i);
            }
         *
         *
         */

        //(2) String  Pool //字符池


        /**
         *
             1. String str ="aaaa";
                 <1. 查找String Pool是否存在“aaaa"对象，如果不存在，则创建”aaaa"对象
                 然后将Stirng Pool中对象的地址返回，赋值给str,这样str就会指向String Pool中的对象
                 <2. 如果存在，则不创建对象，直接将String Pool中的地址返回，赋值给Str。

             2.String str = new String(“aaaa");   //new就会创建新的对象，new 出来的对象都放在堆中
                 <1.查找Stirng Pool中是否存在对象，如果存在，则直接在堆中创建一个字符串对象，则返回堆
                 中字符串对象地址。赋值给str,这样str就指向了堆中对象的地址。
                 <2.如果没有，则现在String Pool中先创建一个”aaaa"对象
         */



    }
}
